<template>
  <el-container class="home-container">
    <!--头部区域-->
      <el-header >
        <div>
          <!--<img src="~assets/heima.png"/>-->
          <span>SYYO</span>
        </div>
        <div>
          <span class="spanTop">{{$store.state.accountId}}</span>
          <el-button type="info" @click="logout">退出</el-button>
        </div>
      </el-header>


    <!--主题区-->
    <el-container>
      <!--侧边栏菜单-->
      <el-aside width="200px">
        <!--菜单区域-->
        <el-menu router background-color="#333744" text-color="#fff" active-text-color="#409EFF">
          <!--静态菜单-->
          <!--首页-->
          <el-menu-item index="/home">
            <template slot="title">
              <!-- 图标 -->
              <i class="el-icon-s-home"></i>
              <!-- 文本 -->
              <span>首页</span>
            </template>
          </el-menu-item>

          <el-menu-item index="/chart">
            <template slot="title">
              <!-- 图标 -->
              <i class="el-icon-s-data"></i>
              <!-- 文本 -->
              <span>demo</span>
            </template>
          </el-menu-item>

          <!--动态菜单-->
          <!-- 一级菜单 -->
          <el-submenu :index="index + '' " v-for="(item, index) in menulist" :key="item.menuId">
            <!-- 一级菜单模板区域 -->
            <template slot="title">
              <!-- 图标 -->
              <i class="el-icon-s-tools"></i>
              <!-- 文本 -->
              <span>{{item.menuName}}</span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item :index="subItem.url + ''"  v-for="subItem in item.children" :key="subItem.menuId">
              <template slot="title">
                <!-- 图标 -->
                <i class="el-icon-s-grid"></i>
                <!-- 文本 -->
                <span>{{subItem.menuName}}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>

      </el-aside>
      <!--右侧内容主体-->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
  import {menuHttp} from 'network/menu'
  import {userHttp} from 'network/user'

  export default {

    data() {
      return {
        // 左侧菜单数据
        menulist: [],
      }
    },
    methods: {
      logout() {
        //清除vuex
        this.$store.commit('clearAll')
        //清除sesion
        window.sessionStorage.clear()
        this.$router.push('/login')
      },
      //获取当前用户的所有菜单
      getMenuList(){
        userHttp.getMenuList().then(res=>{
          if (res.code === 20000){
            this.menulist = res.data
            this.$store.commit('addMenu',res.data)

            this.$message.success(res.message)
          } else{
            this.$message.error(res.message)
          }
        })
      }
    },
    created() {
      this.getMenuList()
    }
  }
</script>

<style lang="less"  scoped>
  .home-container {
    height: 100%;
  }
  .el-header {
    background-color: #373d41;
    display: flex;
    justify-content: space-between;
    padding-left: 0;
    align-items: center;
    color: #fff;
    font-size: 20px;
    > div {
      display: flex;
      align-items: center;
      span {
        margin-left: 20px;
      }
    }
  }

  .el-aside {
    background-color: #333744;
    .el-menu {
      border-right: none;
    }
  }

  .el-main {
    background-color: #eaedf1;
  }

  .iconfont {
    margin-right: 10px;
  }
  .spanTop{
    margin: 0 20px;
  }



</style>
